package com.apes.framework.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 功能：文件工具类
 *
 * @author xul
 * @create 2018-02-12 18:19
 */
public class FileUtil {

    protected static final Logger logger = LogManager.getLogger(FileUtil.class);

    public static InputStream getInputStream(String[] paths, String suffix) throws IOException {
        InputStream is = null;
        String fileName;
        if (paths.length == 1) {
            fileName = paths[0];
            if (fileName.toLowerCase().endsWith(suffix)) {
                is = new FileInputStream(fileName);
            }
        } else if (paths.length == 2) {
            fileName = paths[1];
            if (fileName.toLowerCase().endsWith(suffix)) {
                is = Resources.getResourceAsStream(fileName);
            }
        }
        return is;
    }
}
